package one.stand.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import one.stand.aop.ApiController;
import one.stand.model.ResultModel;
import one.stand.request.GoodSpecRequest;
import one.stand.request.GoodsRequest;
import one.stand.request.GoodstypeRequest;
import one.stand.request.TokenRequest;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 产品信息管理
 * @author Administrator
 */
@RestController
@RequestMapping("crmApi/goods")
@Api(description = "产品信息管理",tags="产品信息管理")
public class GoodsController extends BaseController {

    @PostMapping("/selectGoodsTypeInfo")
    @ApiOperation(value = "根据公司ID查询产品分类（包含商品信息）")
    @ApiImplicitParams({})
    @ApiController(isLogin = true,company = true,card = true,paramClass =GoodstypeRequest.class )
    public ResultModel selectGoodsTypeInfo(@RequestAttribute GoodstypeRequest request){
        
        return crmFegin.selectGoodsTypeInfo(request);
    }

    @PostMapping("/getGoodsTypeInfo")
    @ApiOperation(value = "查询简单商品分类（用于商品分类下拉列表）")
    @ApiImplicitParams({})
    @ApiController(isLogin = true,company = true,card = true,isParam = false)
    public ResultModel getGoodsTypeInfo(GoodstypeRequest request,@RequestAttribute TokenRequest tokenRequest){
        BeanUtils.copyProperties(tokenRequest,request);
        return crmFegin.getGoodsTypeInfo(request);
    }

    @PostMapping("/addGoodsType")
    @ApiOperation(value = "添加/修改商品分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodstypeId", value = "分类id", required = false, paramType = "Integer"),
            @ApiImplicitParam(name = "name", value = "分类名称", required = true, paramType = "String"),
    })
    @ApiController(isLogin = true,company = true,card = true,isBoss = true,paramClass =GoodstypeRequest.class )
    public ResultModel addGoodsType(@RequestAttribute GoodstypeRequest request){
        
        return crmFegin.addGoodsType(request);
    }

    @PostMapping("/delGoodsType")
    @ApiOperation(value = "删除商品分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodstypeId", value = "分类id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company = true,card = true,isBoss = true,paramClass =GoodstypeRequest.class )
    public ResultModel delGoodsType(@RequestAttribute GoodstypeRequest request){
        
        return crmFegin.delGoodsType(request);
    }

    @PostMapping("/moveGoodsType")
    @ApiOperation(value = "上移/下移商品分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodstypeId", value = "分类id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "type", value = "1上移，2下移", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company = true,isBoss = true,paramClass =GoodstypeRequest.class )
    public ResultModel moveGoodsType(@RequestAttribute GoodstypeRequest request){
        
        return crmFegin.moveGoodsType(request);
    }

    @PostMapping("/getGoodsInfo")
    @ApiOperation(value = "查询商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company = true,card = true,paramClass =GoodsRequest.class )
    public ResultModel getGoodsInfo(@RequestAttribute GoodsRequest request){
        
        return crmFegin.getGoodsInfo(request);
    }

    @PostMapping("/addGoodsInfo")
    @ApiOperation(value = "添加商品信息（旧）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品id", paramType = "String"),
            @ApiImplicitParam(name = "goodsName", value = "商品名称", required = true, paramType = "String"),
            @ApiImplicitParam(name = "goodstypeId", value = "分类id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "goodsDetails", value = "商品详情", required = true, paramType = "String"),
            @ApiImplicitParam(name = "ispayment", value = "1线上支付，2其他", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "remark", value = "备注", paramType = "String"),
            @ApiImplicitParam(name = "specIds", value = "商品规格id（逗号隔开）", required = true, paramType = "String"),
            @ApiImplicitParam(name = "goodPhoto", value = "商品图片（逗号隔开）", required = true, paramType = "String"),
            @ApiImplicitParam(name = "coverImg", value = "产品封面图", required = true, paramType = "String"),
    })
    @ApiController(isLogin = true,company = true,card = true,isBoss = true,paramClass =GoodsRequest.class )
    public ResultModel addGoodsInfo(@RequestAttribute GoodsRequest request){
        return crmFegin.addGoodsInfo(request);
    }

    @PostMapping("/addGoodsInfoList")
    @ApiOperation(value = "添加/修改商品信息（新-3.2版本迭代）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品id", paramType = "Integer"),
            @ApiImplicitParam(name = "goodsName", value = "商品名称", required = true, paramType = "String"),
            @ApiImplicitParam(name = "goodstypeId", value = "分类id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "goodsDetails", value = "商品详情", required = true, paramType = "String"),
            @ApiImplicitParam(name = "ispayment", value = "1线上支付，2其他", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "isDistribution", value = "0不是分销商品 1是分销商品 ", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "remark", value = "备注", paramType = "String"),
            @ApiImplicitParam(name = "goodPhoto", value = "商品图片（逗号隔开）", required = true, paramType = "String"),
            @ApiImplicitParam(name = "coverImg", value = "产品封面图", required = true, paramType = "String"),
            @ApiImplicitParam(name = "goodSpecRequestList", value = "商品规格list", required = true, paramType = "List"),
    })
    @ApiController(isLogin = true,company = true,card = true,isBoss = true,paramClass =GoodsRequest.class )
    public ResultModel addGoodsInfoList(@RequestAttribute GoodsRequest request){
        return crmFegin.addGoodsInfoList(request);
    }

    @PostMapping("/addGoodSpecInfo")
    @ApiOperation(value = "添加商品规格信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "specName", value = "类型名称", required = true, paramType = "String"),
            @ApiImplicitParam(name = "specAttribute", value = "属性名", required = true, paramType = "String"),
            @ApiImplicitParam(name = "specNum", value = "库存", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "price", value = "价格(分)", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "parentId", value = "父级id（如果是类型的第一个属性就给0，如果不是就给第一个属性的specId）", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company = true,card = true,isBoss = true,paramClass =GoodSpecRequest.class )
    public ResultModel addGoodSpecInfo(@RequestAttribute GoodSpecRequest request){
        
        return crmFegin.addGoodSpecInfo(request);
    }

    @PostMapping("/transferGoods")
    @ApiOperation(value = "转移产品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品ID", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "goodstypeId", value = "商品类型ID", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company = true,card = true,paramClass =GoodsRequest.class )
    public ResultModel transferGoods(@RequestAttribute GoodsRequest request){
        
        return crmFegin.transferGoods(request);
    }

    @PostMapping("/delGoodsInfo")
    @ApiOperation(value = "删除商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsId", value = "商品id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company = true,card = true,isBoss = true,paramClass =GoodsRequest.class )
    public ResultModel delGoodsInfo(@RequestAttribute GoodsRequest request){
        
        return crmFegin.delGoodsInfo(request);
    }

    @PostMapping("/delGoodSpecInfo")
    @ApiOperation(value = "删除商品规格信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "specId", value = "商品分类id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true,company = true,card = true,isBoss = true,paramClass =GoodSpecRequest.class )
    public ResultModel delGoodSpecInfo(@RequestAttribute GoodSpecRequest request){
        
        return crmFegin.delGoodSpecInfo(request);
    }

}
